package org.crazyit.cloud.use3;


import com.netflix.config.ConfigurationManager;
import com.netflix.hystrix.HystrixCommandProperties;

/**
 * 信号量的方式、
 */
public class SemaphoreMain {

    public static void main(String[] args) throws InterruptedException {
        ///先设置全局配置，设置为信号量的方式去隔离
        ConfigurationManager
                .getConfigInstance()
                .setProperty("hystrix.command.default.execution.isolation.strategy",
                        HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE);
        //信号量默认最大并发数是10，这里设置小一点
        ConfigurationManager
                .getConfigInstance()
                .setProperty("hystrix.command.default.execution.isolation.semaphore.maxConcurrentRequests",2);

        for (int i = 0; i < 6; i++) {
            final int index = i;
            Thread t = new Thread(() -> {
                MyCommand c = new MyCommand(index);
                c.execute();
            });
            t.start();
        }
        Thread.sleep(5000);
    }




}
